package cn.sumpu.app.guoguojie.biz.impl;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.sumpu.app.guoguojie.biz.Weibo;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;
import cn.sumpu.app.guoguojie.util.SinaWeibo;

public class WeiboImpl implements Weibo {

	private final static Logger logger = LoggerFactory
			.getLogger(WeiboImpl.class);

	private String weiboSinaAppCallBack;

	public void setWeiboSinaAppCallBack(String weiboSinaAppCallBack) {
		this.weiboSinaAppCallBack = weiboSinaAppCallBack;
	}

	@Override
	public String openOauth(String type) throws AppBusinessException {
		try {
			return SinaWeibo.openOauth(weiboSinaAppCallBack,type);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("OpenOauth fail", e);
			}
			throw new AppBusinessException(e);
		}
	}

	@Override
	public Map<String, String> oauth(String oauthVerifier,String oauthType) throws AppBusinessException {
		try {
			return SinaWeibo.oauth(oauthVerifier,oauthType);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("oauth fail", e);
			}
			throw new AppBusinessException(e);
		}
	}

	@Override
	public void sendMessage(String text, String accessToken,
			String accessSecret) throws AppBusinessException {
		try {
			SinaWeibo.sendMessage2Sina(text, accessToken, accessSecret);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("OpenOauth fail", e);
			}
			throw new AppBusinessException(e);
		}

	}

	@Override
	public void cancelAttentionWeibo(String accessToken, String accessSecret) throws AppBusinessException {
		try {
			SinaWeibo.cancelAttentionSinaWeibo(accessToken, accessSecret);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("OpenOauth fail", e);
			}
			throw new AppBusinessException(e);
		}

	}

}
